package context;

import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Display;
import javax.microedition.midlet.MIDlet;

public final class Context
{ private static MIDlet MIDLET;
  private static Display DISPLAY;
  
  public static void setMidlet(MIDlet midlet)
  { MIDLET=midlet;
    DISPLAY=Display.getDisplay(MIDLET);
  }

  private static Display getDisplay()
  { if(DISPLAY==null) Debug.ERROR("Context.getDisplay: Context is not initiated");
	  return(DISPLAY);
  }

  public static Displayable setCurrent(Displayable displayable)
  { Displayable prev=getDisplay().getCurrent();
    Debug.println("Context.setCurrent:  displayable="+displayable);
    getDisplay().setCurrent(displayable);
    return(prev);
  }

  
  public static void showError(String msg)  { new ErrorScreen(msg); }

  public static void exit() { MIDLET.notifyDestroyed(); }

}
